package com.joker.aigc.oj.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import com.joker.aigc.oj.domain.entity.RecruitApply;
import com.joker.aigc.oj.mapper.RecruitApplicationMapper;
import com.joker.aigc.oj.service.RecruitApplyService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;

@Service
@Slf4j
@Transactional
public class RecruitApplyServiceImpl extends ServiceImpl<RecruitApplicationMapper, RecruitApply> implements RecruitApplyService {


    @Override
    public IPage<RecruitApply> selectAllRecruitApplicationByAdmin(Integer current) {
        IPage<RecruitApply> c = new Page<>(current, 10);
        return this.baseMapper.selectPage(c, null);
    }

    @Override
    public IPage<RecruitApply> selectAllRecruitApplicationByUser(Integer current) {
        // 每页10
        IPage<RecruitApply> c = new Page<>(current, 10);
        QueryWrapper<RecruitApply> recruitApplicationQueryWrapper = new QueryWrapper<>();
        //  筛选条件为 首先的 申请通过的。
        //  然后 招聘开始时间 < 现在时间 < 招聘结束时间。
        recruitApplicationQueryWrapper.eq("pass", 1)
                .le("start", new Date())
                .ge("end", new Date());

        return this.baseMapper.selectPage(c, recruitApplicationQueryWrapper);


    }

    @Override
    public Integer updateRecruitApplication(RecruitApply recruitApplication) {
        return null;
    }

    @Override
    public Integer addRecruitApplication(RecruitApply recruitApplication) {


        return this.baseMapper.insert(recruitApplication);
    }
}
